﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using V5_EShop._Class.Model;
using System.Data;
using V5_DAL.SqlServer;

namespace V5_EShop._Class.BLL {
    public class BLLGZProduct {
            
    private readonly DALGZProduct dal = new DALGZProduct();
    public BLLGZProduct() { }
    #region  Method
    /// <summary>
    /// 得到最大ID
    /// </summary>
    public int GetMaxId() {
        return dal.GetMaxId();
    }

    /// <summary>
    /// 是否存在该记录
    /// </summary>
    public bool Exists(Guid ID) {
        return dal.Exists(ID);
    }

    /// <summary>
    /// 增加一条数据
    /// </summary>
    public void Add(ModelGZProduct model) {
        dal.Add(model);
    }

    /// <summary>
    /// 更新一条数据
    /// </summary>
    public bool Update(ModelGZProduct model) {
        return dal.Update(model);
    }

    /// <summary>
    /// 删除一条数据
    /// </summary>
    public bool Delete(Guid ID) {
        return dal.Delete(ID);
    }
    /// <summary>
    /// 删除数据
    /// </summary>
    public bool DeleteList(string IDlist) {
        return dal.DeleteList(IDlist);
    }

    /// <summary>
    /// 得到一个对象实体
    /// </summary>
    public ModelGZProduct GetModel(Guid ID) {
        return dal.GetModel(ID);
    }

    /// <summary>
    /// 获得数据列表
    /// </summary>
    public DataSet GetList(string strWhere) {
        return dal.GetList(strWhere);
    }
    
    /// <summary>
    /// 获得数据列表
    /// </summary>
    public DataSet GetList(string strFiled,string strWhere) {
        return dal.GetList(strFiled,strWhere);
    }
    
    /// <summary>
    /// 获得前几行数据
    /// </summary>
    public DataSet GetList(int Top, string strWhere, string filedOrder) {
        return dal.GetList(Top, strWhere, filedOrder);
    }
    
    /// <summary>
    /// 获得前几行数据
    /// </summary>
    public DataSet GetList(string strFiled,int Top, string strWhere, string filedOrder) {
        return dal.GetList(strFiled,Top, strWhere, filedOrder);
    }
    
    /// <summary>
    /// 分页获取数据列表
    /// </summary>
    public DataSet GetList(int PageSize, int PageIndex, string strWhere,string strOrder, ref int RecordCount) {
        return dal.GetList(PageSize, PageIndex, strWhere, strOrder, ref RecordCount);
    }
    
    /// <summary>
    /// 分页获取数据列表
    /// </summary>
    public DataSet GetList(string strFiled,int PageSize, int PageIndex, string strWhere,string strOrder, ref int RecordCount) {
        return dal.GetList(strFiled,PageSize, PageIndex, strWhere, strOrder, ref RecordCount);
    }

    public decimal GetPrice(V5_Model.ModelGZUser user, _Class.Model.ModelGZProduct model)
    {
        decimal prices = Math.Round(model.MaxSalePrice.Value, 2);

        if (user == null)
            return prices;

        model.Specialofferings = model.Specialofferings ?? false;
        if (model.Specialofferings.Value)
        {
            return Math.Round(model.SalePrice1.Value, 2); 
        }
         
        if (user.CustomSaleType != null && user.CustomSaleType > 0)
        { 
            switch (user.CustomSaleType.Value)
            {
                case 1:
                    prices = Math.Round(model.SalePrice1.Value, 2);
                    break;
                case 2:
                    prices = Math.Round(model.SalePrice2.Value, 2);
                    break;
                case 3:
                    prices = Math.Round(model.SalePrice3.Value, 2);
                    break;
                case 4:
                    prices = Math.Round(model.SalePrice4.Value, 2);
                    break;
                case 5:
                    prices = Math.Round(model.MaxSalePrice.Value, 2);
                    
                    var lis = new BLLGZCustomOutPrice().GetModelList(" CustomID = '" + user.ID + "' and ProductID = '"+model.ID+"'");
                    if (lis != null && lis.Count > 0)
                    {
                        prices = Math.Round(lis[0].OutBulkPrice.Value, 2);
                    }

                    break;
            }
        }
        return prices;
    }


    #endregion  Method
    
    


    }
}